import * as React from 'react';
import * as ReactDOM from 'react-dom';
var $ = require("jquery");


var $input = require("./input.js");
var INPUT = $input.INPUT;
var INPUTMLEAVE = $input.INPUTMLEAVE;
/*input label插件*/
var INPUT_LABEL = $input.INPUT_LABEL;
var INPUT_DISPLAY = $input.INPUT_DISPLAY;
/*textarea插件*/
var TEXTAREA = $input.TEXTAREA;
/*验证插件*/
var VALIDE = require("./valide.js").VALIDE;
var SELECT = require("./select-table.js").SELECT;
var LIST_SELECT = require("./list-select-table.js").LIST_SELECT;

var UPIMGAE = require("./upiamge.js").UPIMGAE;


var RADIO = require("./radio.js").RADIO;
var CHECKBOX = require("./radio.js").CHECKBOX;

var LABEL = $input.LABEL;
var LABEL_REMARK = $input.LABEL_REMARK


var SELECT_STATIC = require("./select-static.js").SELECT;
var RADIO_STATIC = require("./radio-static.js").RADIO;

var IN = React.createClass({
    getDefaultProps: function() {
        return {
            type: 'INPUT',
            title: "大哥你先设置个title",
            isStar: false,
            cssLength: 1,
            isShow: true,
            isRefresh: false,
            css: {
                0: "",
                1: "one",
                2: "two",
                3: "three",
                4: "four"
            },
            placeholder: "",
            vaDoneMethod: false,
        };
    },
    componentWillMount: function() {

        if (this.props.param.isShow == false) {
            this.setFormValue("");
        } else {
            this.setFormValue(this.props.param.defaultValue ? this.props.param.defaultValue : "");
        }
    },
    handleBlur: function(value, isDoDone) {

        //console.error("进入验证方法" + value);
        var param = this.props.param,
            vaMessage = "",
            temp = {};
        if (value == "" && param.isStar) {
            param.errorMessage = "不能为空!";
        } else if (param.vaMethod) {
            vaMessage = param.vaMethod(value, this);
            param.errorMessage = vaMessage;
        } else {
            param.errorMessage = true;

        }

        temp[this.props.param.name] = param;
        this.props.changState(temp);
        param.errorMessage && isDoDone != false && this.props.param.vaDoneMethod && this.props.param.vaDoneMethod(value, this);
    },
    setFormValue: function(item) {
        this.props.setFormValue(item);
    },
    changeSelfState: function(item) {
        this.props.changState(temp);
    },
    render: function() {
        //var isShow = this.props.param.isShow==false?"hide":"";
        var isShow = "from-area " + (this.props.param.isShow == false ? "hide" : "");
        //console.log("thi .llllll" + this.props.isShow);
        var cssLength = "from-in-area " + this.props.css[this.props.param.csslength];
        var defaultValue = this.props.param.defaultValue ? this.props.param.defaultValue : "";

        return (
            <div className={cssLength}>
                        {(() => {
                            switch (this.props.param.type.toLocaleUpperCase()) {
                                case "INPUT":
                                    return (
                                        <INPUT placeholder={this.props.param.placeholder} name={this.props.param.name}
                                               setFormValue={this.setFormValue} handleBlur={this.handleBlur}
                                               defaultValue={defaultValue}/>
                                    )
                                case "INPUTMLEAVE":
                                    return (
                                        <INPUTMLEAVE placeholder={this.props.param.placeholder} name={this.props.param.name}
                                               setFormValue={this.setFormValue} handleBlur={this.handleBlur}
                                               defaultValue={defaultValue}/>
                                    )
                                case "INPUT_DISPLAY":
                                    return (
                                        <INPUT_DISPLAY placeholder={this.props.param.placeholder} name={this.props.param.name}
                                               setFormValue={this.setFormValue} handleBlur={this.handleBlur}
                                               defaultValue={defaultValue}/>
                                    )
                                case "INPUT_LABEL":
                                    return (
                                        <INPUT_LABEL placeholder={this.props.param.placeholder} name={this.props.param.name}
                                                     setFormValue={this.setFormValue} handleBlur={this.handleBlur}
                                                     subTitle={this.props.param.subTitle} defaultValue={defaultValue}/>
                                    )
                                case "TEXTAREA":
                                    return (
                                        <TEXTAREA placeholder={this.props.param.placeholder} name={this.props.param.name}
                                                  setFormValue={this.setFormValue} handleBlur={this.handleBlur}
                                                  defaultValue={defaultValue}/>
                                    )
                                case "SELECT":
                                    return (
                                        <SELECT vaIsDo={this.props.param.vaIsDo} defaultShowName={this.props.param.defaultShowName} placeholder={this.props.param.placeholder} name={this.props.param.name}
                                                setFormValue={this.setFormValue} handleBlur={this.handleBlur} keyName={ this.props.param.keyName}
                                                defaultValue={defaultValue} valuekey={this.props.param.valuekey} isAuto={this.props.param.isAuto===false?false:true} />
                                    )
                                case "SELECT_BY_PARAM":
                                    return (
                                            <SELECT vaIsDo={this.props.param.vaIsDo} defaultShowName={this.props.param.defaultShowName} placeholder={this.props.param.placeholder} name={this.props.param.name} changeSelfState={this.changeSelfState}
                                                setFormValue={this.setFormValue} handleBlur={this.handleBlur} keyName={ this.props.param.keyName}
                                                defaultValue={defaultValue} valuekey={this.props.param.valuekey} url={this.props.param.url}
                                                searchParam={this.props.param.searchParam} isAuto={this.props.param.isAuto} reFreshNum={this.props.param.reFreshNum} />
                                        )
                                 case "SELECT_STATIC":
                                    return (
                                            <SELECT_STATIC defaultShowName={this.props.param.defaultShowName} placeholder={this.props.param.placeholder} name={this.props.param.name} changeSelfState={this.changeSelfState}
                                                setFormValue={this.setFormValue} handleBlur={this.handleBlur} keyName={ this.props.param.keyName}
                                                defaultValue={defaultValue} valuekey={this.props.param.valuekey} Data={this.props.param.Data}
                                                searchParam={this.props.param.searchParam} isAuto={this.props.param.isAuto} reFreshNum={this.props.param.reFreshNum} />
                                        )
                                case "RADIO":
                                    return (
                                            <RADIO placeholder={this.props.param.placeholder} name={this.props.param.name} changeSelfState={this.changeSelfState}
                                                setFormValue={this.setFormValue} handleBlur={this.handleBlur} keyName={ this.props.param.keyName}
                                                defaultValue={defaultValue} valuekey={this.props.param.valuekey} url={this.props.param.url}
                                                searchParam={this.props.param.searchParam}/>
                                        )
                                case "RADIO_STATIC":
                                    return (
                                            <RADIO_STATIC placeholder={this.props.param.placeholder} name={this.props.param.name} changeSelfState={this.changeSelfState}
                                                setFormValue={this.setFormValue} handleBlur={this.handleBlur} keyName={ this.props.param.keyName}
                                                defaultValue={defaultValue} valuekey={this.props.param.valuekey} data={this.props.param.data}
                                                searchParam={this.props.param.searchParam}/>
                                        )
                                case "CHECKBOX":
                                    return (
                                            <CHECKBOX placeholder={this.props.param.placeholder} name={this.props.param.name} changeSelfState={this.changeSelfState}
                                                setFormValue={this.setFormValue} handleBlur={this.handleBlur} keyName={ this.props.param.keyName}
                                                defaultValue={defaultValue} valuekey={this.props.param.valuekey} url={this.props.param.url}
                                                searchParam={this.props.param.searchParam}/>
                                        )
                                case "LIST_SELECT":
                                    return (
                                        <LIST_SELECT defaultShowName={this.props.param.defaultShowName} placeholder={this.props.param.placeholder} url={this.props.param.url || ''} name={this.props.param.name}
                                                setFormValue={this.setFormValue} handleBlur={this.handleBlur} keyName={ this.props.param.keyName}
                                                defaultValue={defaultValue} valuekey={this.props.param.valuekey}/>
                                    )
                                case "UPIMAGE":
                                    return (
                                        <UPIMGAE name={this.props.param.name} setFormValue={this.setFormValue} handleBlur={this.handleBlur}
                                                 defaultValue={defaultValue}/>
                                    )
                                case "LABEL":
                                    return (
                                        <LABEL defaultValue={defaultValue}/>
                                    );
                                case "LABEL_REMARK":
                                    return (
                                        <LABEL_REMARK defaultValue={defaultValue}/>
                                    );
                                default:
                                    return (
                                        <INPUT placeholder={this.props.param.placeholder} name={this.props.param.name}
                                               setFormValue={this.setFormValue} handleBlur={this.handleBlur}
                                               defaultValue={defaultValue}/>
                                    )
                            }
                        })()}
                        <VALIDE errorMessage={this.props.param.errorMessage} name={this.props.name}/>
                    </div>
        )
    }

})
module.exports = {
    IN: IN,
}